<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
    <title>Document</title>
    <style>
        .box {
          width: 300px;
          height: 300px;
          /* background-color: red; */
          border: 1px solid #000;
        }
      </style>
</head>
<body>
    <div class="box"></div>
    <script>
        const oBox = document.querySelector('.box')

        //鼠标移动事件 供 lodash使用
        /* function center(e){
            console.log('center');
            console.log(e.target);
            console.log(this);
        } */

        function center (){
            this.style.background = 'red'
        }

        function leave(){
            this.style.background = ''
        }
        oBox.onmousemove = _.throttle(center,300,{
            // lodash的节流函数配置项提供了两个配置,leading控制节流返回的回调函数是否在初始化的时候触发,trailing控制节流返回的回调函数是否在最后也触发
            leading:true,
            trailing:false
        })
        oBox.onmouseleave = leave
    </script>
</body>
</html>